package com.echoplots.redis.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.echoplots.redis.entity.User;
import com.echoplots.redis.utils.RedisUtil;

@RequestMapping("/redis")
@RestController
public class RedisController {

	private static int ExpireTime = 60; // redis中存储的过期时间60s

	@Resource
	private RedisUtil redisUtil;

	@RequestMapping("set")
	public boolean redisset(String key, String value) {
		User user = new User();
		user.setId(Long.valueOf(1));
		user.setGuid(String.valueOf(1));
		user.setName("zhangsan");
		user.setAge(String.valueOf(20));
		user.setCreateTime(new Date());

		// return redisUtil.set(key,userEntity,ExpireTime);

		return redisUtil.set(key, value);
	}

	@RequestMapping("get")
	public Object redisget(String key) {
		return redisUtil.get(key);
	}

	@RequestMapping("expire")
	public boolean expire(String key) {
		return redisUtil.expire(key, ExpireTime);
	}
}